/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package backingBean;

import entities.Members;
import java.io.Serializable;
import javaServices.MemberManager;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author michael
 */
@ManagedBean(name ="login")
@SessionScoped
public class LoginMB implements Serializable{
    
    private Members members;
    private Members membreencours;
    private Members membrevisite;

    public Members getMembreencours() {
        return membreencours;
    }

    public void setMembreencours(Members membreencours) {
        this.membreencours = membreencours;
    }

    public Members getMembrevisite() {
        return membrevisite;
    }

    public void setMembrevisite(Members membrevisite) {
        this.membrevisite = membrevisite;
    }
    
    
    @PostConstruct
    public void initData(){
        members = new Members();
    }

    public Members getMembers() {
        return members;
    }

    public void setMembers(Members members) {
        this.members = members;
    }
       
    
    public String login(){
        //int Val = 0;
        String Check; 
        //MemberService.getUserById(Val);
        FacesContext context = FacesContext.getCurrentInstance();
        
        Members tempMembers = MemberManager.getUserByEmail(members.getEmailMembers());
        context.getExternalContext().getSessionMap().put("member", tempMembers);     
        
        
        if(tempMembers != null){
            Check = "profile";
        }
        else{
            Check = "error";
        }
        
        return Check;
    }
    
    public String logout() {
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
        return "index";
    }
    
}
